package com.utn.tp.integrador.adaptadores;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.utn.tp.integrador.R;
import com.utn.tp.integrador.entidades.Accion;

public class RegistroAdapter extends BaseAdapter {
	private ArrayList<Accion> reg;
	private LayoutInflater inflater;

	public RegistroAdapter(Context c) {
		reg = new ArrayList<Accion>();
		inflater = LayoutInflater.from(c);
	}

	public void clear() {
		reg.clear();
	}

	public void addRegistro(Accion registro) {
		if (registro != null) {
			reg.add(registro);
		}
	}

	/*
	 * public void sort(Comparator<Contacto> comparator) { Collections.sort(reg,
	 * comparator); }
	 */

	@Override
	public int getCount() {
		return reg.size();
	}

	@Override
	public Object getItem(int position) {
		return reg.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		Holder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.lista_item_registro, null);
			holder = getHolder();
			holder.txtReg = (TextView) convertView
					.findViewById(R.id.txtTipoAccion);

			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}

		Accion registro = (Accion) getItem(position);
		holder.txtReg.setText(registro.toString());

		return convertView;
	}

	protected Holder getHolder() {
		return new Holder();
	}

	class Holder {
		private TextView txtReg;
	}
}
